﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace SimpleConnection_UDP_WIN.utils
{

    public partial class ToastForm : Form
        {
            private Timer timer;

            public ToastForm(string message)
            {
                InitializeToast(message);
            }

            private void InitializeToast(string message)
            {
                // 设置窗体属性
                FormBorderStyle = FormBorderStyle.None;
                BackColor = Color.SeaGreen;
                TopMost = true;
                ShowInTaskbar = false;
  

            // 添加文本标签
            Label label = new Label
            {
                Text = message,
                ForeColor = Color.White,
                Font = new Font("微软雅黑", 12),
                AutoSize = true,
                Location = new Point(12, 12),
                Margin = new Padding(16)
             
            };
            Controls.Add(label);

            Width = label.Width;
            Height = label.Height;
           
            //label.TextAlign = ContentAlignment.MiddleCenter;

                // 设置窗体位置
                int screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
                int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
                Location = new Point(screenWidth - Width - 10, screenHeight - Height - 10);

                // 设置定时器
                timer = new Timer();
                timer.Interval = 3000; // 3秒后关闭窗体
                timer.Tick += Timer_Tick;
                timer.Start();
            }

            private void Timer_Tick(object sender, EventArgs e)
            {
                timer.Stop();
                Close();
            }
        }

}
